package com.yuandian.middle.platform.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.middle_platform.po.AlarmDetailPojo;
import com.yuandian.api.middle_platform.po.OrgAbilityParam;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.middle.platform.enums.AlarmLevelEnum;
import com.yuandian.middle.platform.mapper.AlarmMapper;
import com.yuandian.middle.platform.service.IAlarmService;
import com.yuandian.utils.PageDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 说明：告警查询接口实现
 * @Author tianlr
 * @Date 2023/5/24 17:12
 */

@Service
public class AlarmServiceImpl implements IAlarmService {

    @Autowired
    private AlarmMapper alarmMapper;

    /**
     * 告警查询接口
     * @param param
     * @return
     */
    @Override
    public R selectDataAlarm(OrgAbilityParam param) {
        if (param.getPageNum() <= 0) {
            param.setPageNum(1);
        }
        if (param.getPageSize() <= 0) {
            param.setPageSize(10);
        }
        IPage<AlarmDetailPojo> page = new Page<>(param.getPageNum(), param.getPageSize());
        List<AlarmDetailPojo> list =  alarmMapper.selectAlarm(page, param);
        if (list != null && list.size() > 0) {
            for (AlarmDetailPojo pojo : list) {
                pojo.setLevelName(AlarmLevelEnum.getItemValue(pojo.getLevelId()));
            }
        }
        return R.ok(new PageDataInfo(page.getTotal(), list));
    }
}
